<?php
/**
 * Created by PhpStorm.
 * User: liyang
 * Date: 2017/12/5  Time: 上午11:53
 * Description:人脸识别
 */


class UserVerifaceRecordModel extends BaseModel
{


    protected $table = 'user_veriface_record';

    public function hasManyConsultation()
    {
        return self::hasMany('ConsultationModel', 'rid', 'id');
    }

    public static function getUsedCnt($uid, $pid)
    {
        return self::query()
            ->where(['uid' =>$uid, 'pid' => $pid])
            ->whereBetween('create_time', [date('Y-m-d').' 00:00:00', date('Y-m-d').' 23:59:59'])
            ->count();
    }

    /**
     * @param $uid
     * @param $pid
     * @return self
     */
    public static function getLastPassReocrd($uid, $pid)
    {
        return self::query()->where(['uid' => $uid, 'pid' => $pid, 'auth_result' =>3])
            ->orderBy('id', 'des')
            ->first();
    }

    public function getScore()
    {
        return $this->score;
    }

    public static function getChecking($uid, $pid)
    {
        /** @var self $result */
        $result = self::query()->where(['uid' => $uid, 'pid' => $pid, 'auth_result' => 2])
            ->orderBy('id', 'DESC')
            ->first();

        return $result;
    }

    public static function getLast($uid, $pid)
    {
        /** @var self $result */
        $result = self::query()->where(['uid' => $uid, 'pid' => $pid,])
            ->orderBy('id', 'DESC')
            ->first();

        return $result;
    }
}